﻿@model List<Hetang.Models.DataContext.tbl_Job>
@{
    ViewBag.Title = "招聘信息管理";
    ViewBag.SettingTitle = "招聘信息管理";
    Layout = "~/Views/Shared/_UserLayout.cshtml";
}

<div class="bs-docs-grid">
    <div class="job-list" @(Model.Any() ? "" : "style=display:none;")>
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>操作</th>
                    <th>职位编号</th>
                    <th>职位名称</th>
                    <th>招聘部门</th>
                    <th>有效期至</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var job in Model)
                {
                    <tr>
                        <td>
                            <input type="checkbox" value="@job.Id" /></td>
                        <td>@job.Id</td>
                        <td>@job.JobName</td>
                        <td>@job.Department</td>
                        <td>@job.ValidDate.ToString("yyyy年MM月dd日")</td>
                        <td>
                            <a href="/job/view/@job.Id" target="_blank" action="check" action-data="@job.Id"><i class="icon-search"></i> 查看</a>
                            <a href="/user/company/editjob/@job.Id" target="_blank" action="modify" action-data="@job.Id"><i class="icon-edit"></i> 更改</a>
                            <a href="javascript:void(0);" title="将有效期延长一个月" action="update" action-data="@job.Id"><i class="icon-refresh"></i> 更新</a>
                            <a href="javascript:void(0);" action="delete" action-data="@job.Id"><i class="icon-trash"></i> 删除</a></td>
                    </tr>
                }
            </tbody>
        </table>
        <hr />
        <div class="control">
            <a href="javascript:void(0);" action="selectall">全选</a> / <a href="javascript:void(0);" action="remove">取消全选</a>
        </div>
    </div>
    <h3 id="hide" class="span12 muted" @(Model.Any() ? "style=display:none;" : "")>你还没有发布过招聘信息，现在 @Html.ActionLink("发布", "publish", "company", null, new { area = "user" })一条吗？</h3>
</div>

<script type="text/javascript">
    $(".table a").click(function () {
        var action = $(this).attr("action");
        var jid = $(this).attr("action-data");
        var tr = $(this);

        switch (action) {
            case "check":                
                break;
            case "modify":
                break;
            case "update":
                break;
            case "delete":
                if (confirm("真的要删除吗？")) {
                    $.post("/user/company/deletejob", { "jid": jid }, function (data) {
                        if (data == "ok") {
                            tr.parent().parent().fadeOut(500).remove();
                            if ($(".table tr").length <= 1) {
                                $(".job-list").hide();
                                $("#hide").show();
                            }
                        }
                        else {
                            alert("系统有点繁忙，请刷新页面再试一次！");
                        }
                    });
                }
                break;
            default:
                alert("你想做什么操作？看我能不能帮到你？");
        }
    });

    $(".control a").click(function () {
        var action = $(this).attr("action");

        switch (action) {
            case "selectall":
                $(".table :checkbox").each(function (index) {                    
                    $(this).prop('checked', true);
                });
                break;
            case "remove":
                $(".table :checkbox").each(function (index) {                    
                    $(this).prop('checked', false);
                });
                break;
        }
    });
</script>
